package com.son.hotel.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.son.hotel.common.ErrorCode;
import com.son.hotel.domain.Rooms;
import com.son.hotel.execption.BusinessException;
import com.son.hotel.mapper.RoomsMapper;
import com.son.hotel.service.RoomsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 孙一卓
* @description 针对表【rooms】的数据库操作Service实现
* @createDate 2025-06-24 14:37:43
*/
@Service
public class RoomsServiceImpl extends ServiceImpl<RoomsMapper, Rooms> implements RoomsService {


    @Autowired
    private RoomsMapper roomsMapper;

    /**
     * 修改房间的状态，如果是已住则改成空闲，如果是空闲则改成已住
     */
    @Override
    public void updateRoomStatus(Rooms rooms){
        if (rooms.getStatus() == 0){
            rooms.setStatus(1);
        }else {
            rooms.setStatus(0);
        }
        int res = roomsMapper.updateById(rooms);
        if (res <= 0){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"插入失败");
        }
    }
}




